
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  pool.bean;

import java.util.Hashtable;
import java.util.Vector;

import logger.PoolLogger;
import dbmanager.DBManager;

import pool.tablename.Rate_master;

import utility.ConvertToLower;



public class Rate_master_Bean extends SubBean
{	
	private String tableName = "rate_master";
	private Vector<Object> RateVector = new Vector<Object>();;
	
	private Hashtable<Object,Object> oldTransactionHash;
	
	private Rate_master objRate;
	
	private Hashtable<Object,Object> ViewHashtable = new Hashtable<Object, Object>();
	//private String tid;
	//private RequestParameter reqParam;
	//private GetIdName gin;
	//private String tableName = "rate_master ";
	//private String process = "add";
	//private Hashtable<Object,Object> newTransactionHash;
	PoolLogger pl;
	
	public Rate_master_Bean() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	/**
	 * 
	 * @param RateVector vector of properties of Trans_property_details
	 */
	
	public void setPropertyVector(Hashtable<Object,Object> PropertyHash)
	{	
		Hashtable<Object,Object> propertyHash = new Hashtable<Object, Object>();
		propertyHash.putAll(PropertyHash);
		
		propertyHash.putAll(gin.convertMasterId(propertyHash, tableName,process));
		propertyHash = ConvertToLower.convertHashKey(propertyHash);
		RateVector.add(propertyHash);
		
	}
	
	@SuppressWarnings("unchecked")
	public void setPropertyVector(Vector<Object> vector)
	{
		
		for(Object object : vector)
		{
			Hashtable<Object,Object> propertyHash = new Hashtable<Object, Object>();
			
			propertyHash = (Hashtable<Object, Object>)object;	
			propertyHash = ConvertToLower.convertHashKey(propertyHash);
			propertyHash.putAll(gin.convertMasterId(propertyHash, tableName,process));
			
			
			RateVector.add(propertyHash);
		}
		
		
	}
	/**
	 * Insert into Rate_master
	 *
	 */
	@SuppressWarnings("unchecked")
	public StringBuffer insert()
	{
		DBManager.setBeforeCommit();
		objRate = new Rate_master();
		objRate.initPool();
		objRate.setRequestParameter(reqParam);
		objRate.setRateMap(oldTransactionHash);
		StringBuffer sbrDTB = new StringBuffer();
		
		objRate.setPropertyVector(RateVector);
		sbrDTB.append(objRate.getInsert());

		boolean flag = objRate.getResult();
		DBManager.setAfterCommit(flag);
		
		System.out.println(sbrDTB.toString());
		pl.info(sbrDTB.toString());
		pl.debug(sbrDTB.toString());
		pl.warn(sbrDTB.toString());
		pl.fatal(sbrDTB.toString());
		pl.error(sbrDTB.toString());
		pl.trace(sbrDTB.toString());
		
		return sbrDTB;
	}

	
	public StringBuffer update() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	public void setViewHashtable(Hashtable<Object, Object> hashtable) 
	{
		Hashtable<Object,Object> PropertyHash = new Hashtable<Object, Object>();
		
		PropertyHash.putAll(hashtable);
		PropertyHash = gin.getHashMapOfValues(PropertyHash);
		PropertyHash = ConvertToLower.convertHashKey(PropertyHash);
		PropertyHash.putAll(gin.convertMasterId(PropertyHash, tableName, process));
		
		ViewHashtable.putAll(PropertyHash);
	}
	

	public StringBuffer view() 
	{
		
		 StringBuffer sbrDTB = new StringBuffer();
		 
		 objRate = new Rate_master();
		 objRate.setRequestParameter(reqParam);
		 objRate.setViewHashtable(ViewHashtable);
		 
		 sbrDTB.append(objRate.getView());
		 
		return sbrDTB;	
	}

	@Override
	public StringBuffer delete() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
/*	public void setTable(String tableName)
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		this.tableName = tableName;
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.bean","Rate_master_Bean","setTable",t.duration());
		
	}
	public void setProcess(String process)
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		this.process = process;
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.bean","Rate_master_Bean","setProcess",t.duration());
		
	}
	
	public void setDBManager(DBManager sqlDB)
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		this.sqlDB = sqlDB;
		gin = new GetIdName(this.sqlDB);
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.bean","Rate_master_Bean","setDBManager",t.duration());
	}
	
	public void setReqParam(RequestParameter reqParam) 
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		this.reqParam = reqParam;
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.bean","Rate_master_Bean","setReqParam",t.duration());
	}*/
	/*public static void main(String[] args) 
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		Rate_master_Bean prop = new Rate_master_Bean();
		prop.setDBManager();
		Hashtable<Object, Object> old = new Hashtable<Object, Object>();
		
		old.put("item", "Lux");
		old.put("rate", "45445533534");
		old.put("Buysell", "nmmnnn");
		old.put("usergroup", "VG");
			
		RequestParameter req = new RequestParameter();
		req.setUsername("+919922930640");
		req.setMessage("System Message");
		req.setPassword("123");
		req.setRequest("rate_master");
		req.setProcess("add");
		
	
		prop.setReqParam(req);
		prop.setReqParam(req);
		
		prop.setPropertyVector(old);
		prop.insertRate_master();
		
		db.closeConnection();
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.bean","Rate_master_Bean","main",t.duration());
		
	}*/

	
}
